package xyz.o0o0o.demo.ActiveMQDemo;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.ObjectMessage;
import javax.jms.Session;

import org.apache.activemq.ActiveMQConnectionFactory;

public class ReceiveObjectMessage {

	public static void main(final String[] args) throws Exception {
		final ConnectionFactory connFactory = new ActiveMQConnectionFactory();

		final Connection conn = connFactory.createConnection();
		conn.start();  
		final Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

		final Destination dest = sess.createQueue("ObjectQueue");

		final MessageConsumer consumer = sess.createConsumer(dest);

		Message message = consumer.receive(1000);
		
		if (message instanceof ObjectMessage) {
			User user =(User) ((ObjectMessage) message).getObject();
			System.out.println("Received: " + user);
		} else {
			System.out.println("Received: " + message);
		}
		conn.close();
	}
}